package gui.panels.play;

import gui.utils.ComponentUtils;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class SpeechPanel extends JPanel {

    private static final long serialVersionUID = 1L;

    private JTextArea textArea;
    private Image cloudImage;
    
	public SpeechPanel(String text) {
	    this();
	    changeText(text);
	}
	
	public SpeechPanel() {
	    buildPanel();
	}
	
	@SuppressWarnings("serial")
    private void buildPanel() {

	    cloudImage = ComponentUtils.readImageIcon("speech_cloud.png").getImage();
	    
	    Box box = Box.createVerticalBox();
	    box.add(Box.createVerticalStrut(calculateSpace()));
	    
	    textArea = new JTextArea() {
	        public void paintComponent(Graphics g) {
	            ComponentUtils.setAntiAliased(g);
	            super.paintComponent(g);
	        }
	    };
	    textArea.setFont(new Font("Tahoma", Font.BOLD, 16));
	    textArea.setEditable(false);
	    textArea.setOpaque(false);
	    textArea.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
	    
	    box.add(textArea);
	    add(box); 
	    
	}
	
	private int calculateSpace() {
	    return 55;
    }

    public void changeText(String text) {
	    String reformatedText = ComponentUtils.addLineBreaks(text, 25);
	    textArea.setText(reformatedText);
	}
	
	@Override
	public void paintComponent(Graphics g) {
	    super.paintComponent(g);
	    g.drawImage(cloudImage, 0, 0, getWidth(), getHeight(), null);
	}
	
}
